//
//  NSDictionary+Utility.m
//  eGiftr
//
//  Created by Phien Tram on 9/3/13.
//  Copyright (c) 2013 eGiftr. All rights reserved.
//

#import "NSDictionary+Utility.h"

@implementation NSDictionary (Utility)


- (NSString *)parameterize
{
    NSString *params = @"";
    for (NSString *key in self.allKeys) {
        //assume that all values should be string
        NSString *value = [self objectForKey:key];
        if (params.length == 0) {
            params = [params stringByAppendingFormat:@"%@=%@", key, value];
        } else {
            params = [params stringByAppendingFormat:@"&%@=%@", key, value];
        }
    }
    
    return params;
}

- (id)objectOrNilForKey:(id)aKey
{
    id object = [self objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}

@end
